
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->

    <title>laravel相册</title>

    <!-- 加载 CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
     <link href="/css/app.css" rel="stylesheet">

      <!-- 加载 js -->
    <script src="/js/jquery.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/masonry.pkgd.min.js"></script>
    <script src="/js/imagesloaded.pkgd.min.js"></script>
</head>
<body>

    <!-- bootstrap 导航条 -->
    <nav class="navbar navbar-default">
      <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <!-- 导航按钮 此网站不需要 -->
            <!-- <li><a href="#">Link</a></li> -->
          </ul>
        </div>
      </div>
    </nav>

    <!-- bootstrap 容器 -->
    <div class="container">
        <!-- 显示提示消息 -->
                <!-- 网站主体内容 -->
        
<!-- 错误信息 -->

<!-- 创建相册：弹出框按钮 -->
<button type="button" class="btn btn-primary" style="margin-bottom:10px" data-toggle="modal" data-target="#createAlbum">
创建相册
</button>


<!-- 创建相册：弹出框 -->
<div class="modal fade" id="createAlbum" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">创建相册</h4>
      </div>
      <div class="modal-body">
          <form class="form-horizontal" id="photo">
            <div class="form-group">
              <label for="name" class="col-sm-2 control-label">封面图片</label>
              <div class="col-sm-10">
                <input type="file" name="coverpicture" required>
              </div>
            </div>
            <div class="form-group">
              <label for="name" class="col-sm-2 control-label">相册名称</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="name" name="name" required>
              </div>
            </div>
            <div class="form-group">
              <label for="intro" class="col-sm-2 control-label">相册描述</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="intro" name="description">
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button  class="btn btn-primary sub">创建</button>
              </div>
            </div>
          </form>
      </div>
    </div>
  </div>
</div>
<!-- 相册展示 -->
<div class="row masonry">
    @foreach($data as $key => $value)
      <div class="col-md-3 col-sm-4 col-xs-6 album  item">
        <a href="/photo/detail/{{$value -> id}}">
            <div class="panel panel-default">
              <div class="panel-body">
                  <img class="img-responsive" src="{{$value -> coverpicture}}">
                  <p class="album-name">{{$value -> name}}</p>
                  <p class="album-intro">{{$value -> description}}</p>
             </div>
            </div>
        </a>
    </div>
    @endforeach
</div>

<!--瀑布流-->
<script>
 var container = $('.masonry');
  container.imagesLoaded(function() {
    container.masonry({
    itemSelector: '.item',
    isAnimated: true,
    });
});

$(function(){
  //所有的请求标头
   $.ajaxSetup({
        headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
    });

  //发送ajax
  $('.sub').click(function(){
      
      $('.fade').addClass('hide');
      var formData = new FormData($("#photo")[0]);
           $.ajax({  
                url: '/photo/image' ,  
                type: 'POST',  
                data: formData, 
                dataType: 'json',
                async: true, 
                cache: false,  
                contentType: false,  
                processData: false,  
                success: function (returndata) {  
                    location.reload();
                },  
                error: function (returndata) {  
                    alert('创建失败');
                $('.fade').removeClass('hide');

                }  
           });

    return false;
  });

});

</script>
</body>
</html>
